package com.applcn.user.controller.merchant;

import com.applcn.core.base.Result;
import com.applcn.user.constant.AuthRangeEnum;
import com.applcn.user.dto.merchant.DeleteMenuReqDTO;
import com.applcn.user.dto.merchant.SaveOrChangeMenuReqDTO;
import com.applcn.user.service.MenuService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * com.applcn.user.controller.merchant
 * Description:
 *
 * @author: 大妖怪
 * @date: 2020-03-12 01:20
 */
@RestController
@RequestMapping("/api/user/menu")
@RequiredArgsConstructor
public class MenuController {

    private final MenuService menuService;

    /**
     * 获取导航菜单(动态路由)
     *
     * @return
     */
    @GetMapping("/navigation")
    public Result navigation() {
        return menuService.getCurrentUserMenuList(AuthRangeEnum.MERCHANT);
    }

    /**
     * 根据父菜单id获取菜单列表
     * 若要获取最外层菜单，parentId为0
     *
     * @param parentId
     * @return
     */
    @GetMapping("/menuList")
    public Result menuList(@RequestParam("parentId") Long parentId) {
        return menuService.menuList(parentId);
    }

    /**
     * 获取目录列表
     *
     * @param parentId
     * @return
     */
    @GetMapping("/catalogList")
    public Result catalogList(@RequestParam("parentId") Long parentId) {
        return menuService.catalogList(parentId);
    }

    /**
     * 通过id获取菜单
     *
     * @param id
     * @return
     */
    @GetMapping("/menuDetail")
    public Result menuDetail(@RequestParam("id") Long id) {
        return menuService.menuDetail(id);
    }

    /**
     * 添加/修改菜单
     *
     * @param dto
     * @return
     */
    @PostMapping("/saveOrChangeMenu")
    public Result saveOrChangeMenu(@RequestBody SaveOrChangeMenuReqDTO dto) {
        return menuService.saveOrChangeMenu(dto);
    }

    /**
     * 批量删除菜单
     *
     * @return
     */
    @PostMapping("/deleteMenuByIds")
    public Result deleteMenuByIds(@RequestBody DeleteMenuReqDTO dto) {
        return menuService.deleteMenuByIds(dto);
    }
}
